﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WoChu.RfClient.Entity;
using WoChu.RfClient.Common;
using WoChu.CF.BaseFrame.Util;

namespace WoChu.RfClient.Duty
{
    public partial class FrmOffShelvesOrder : Form
    {
        public FrmOffShelvesOrder()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 箱号
        /// </summary>
        public static GoodsBoxes goodsBox = new GoodsBoxes();


        private static List<OffShelvesInfo> lstOffCellNo = null;
         
 
        //private static List<LocationGoodsInfo> _lstLocationGoods = null;
        private static List<OffShelvesInfo> lstOffShelves = null;
         
        //状态加载事件
        private void FrmOffShelvesOrder_Load(object sender, EventArgs e)
        { 
            //DataSet dtCellNo = Duty.OffShelvesOrderUIRule.NewInstance.GetOffCellNoInfo(LoginBean.Instance.USERCODE);
            lstOffCellNo = Duty.OffShelvesOrderUIRule.NewInstance.GetOffCellNo(LoginBean.Instance.USERCODE);
            if (lstOffCellNo == null)
            {
                MessageBox.Show("没有指令下架数据，请先在PC端做数据！");
                this.Close();
                return;
            }
            if (lstOffCellNo == null) return;
            this.cbbCellNo.DataSource = lstOffCellNo;
            this.cbbCellNo.DisplayMember = "CELLNO";
            this.cbbCellNo.ValueMember = "CELLNO";
        }
 
        //获取下架指令
        private void btnShelves_Click(object sender, EventArgs e)
        {

            try
            { 
                if (string.IsNullOrEmpty(cbbCellNo.Text.Trim()))
                {
                    MessageBox.Show("请选择库号！");
                    return;
                }
                if (string.IsNullOrEmpty(txtBatchNo.Text.Trim()))
                {
                    MessageBox.Show("请输入批次号！");
                    return;
                }
                DateTime offDT;
                FrmDateTime fdt = new FrmDateTime();
                fdt.ShowDialog();
                if (FrmDateTime.IsOK)
                {
                    offDT = Convert.ToDateTime(FrmDateTime.offDate.ToString("yyyy-MM-dd"));
                }
                else
                {
                    return;
                }
                if (lstOffShelves!=null)
                {
                    //MessageBox.Show("列表中有数据未提交，不能获取指令数据！");
                    if (MessageBox.Show("是否清空现有数据，重新获取", "提示消息", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
                        return;
                     
                }
                string cellNo=cbbCellNo.Text.Trim();
                string batchNo =txtBatchNo.Text.Trim();
  

                lstOffShelves = Duty.OffShelvesOrderUIRule.NewInstance.GetOffShelvesInfo(cellNo,batchNo,LoginBean.Instance.USERCODE,offDT);
                if (lstOffShelves == null)
                {
                    RefData();
                    MessageBox.Show("没有匹配条件的指令数据！");
                    return;
                }
                else if(lstOffShelves.Count>0)
                {

                    foreach (OffShelvesInfo _offShelvesInfo in lstOffShelves)
                    {
                        _offShelvesInfo.EDITOR = LoginBean.Instance.USERCODE; 
                    }
                    bool isSetFlag = Duty.OffShelvesOrderUIRule.NewInstance.SetOffShelvesState("执行",lstOffShelves).Params;
                    if (isSetFlag)
                    {
                        MessageBox.Show("指令数据，获取成功！");
                    }
                    iSort = lstOffShelves.Count;
                }
                RefData();
            }
            catch (Exception ex)
            {
                WoChu.CF.BaseFrame.Util.MessageBoxEx.Show(ex); 
            }
            finally
            {
                txtGoodsBatchCode.Focus();
                txtGoodsBatchCode.SelectAll();
            }
        }

        private static int iSort = 0;
        //排序
        private void Sort(OffShelvesInfo offShelvesInfo)
        {
            offShelvesInfo.Sort = iSort;
            lstOffShelves.Sort((x, y) =>
            {
                return x.LOCATIONCODE.CompareTo(y.LOCATIONCODE);
            });
            this.dtGridOffShelves.Refresh();

            offShelvesInfo.Sort = iSort++;
        }
        //显亮当前行
        private void SelectionBright()
        {
            if (lstOffShelves == null )return;
            if (lstOffShelves.Count <= 0) return;
            //设置已扫描的为加亮
            if (string.IsNullOrEmpty(txtGoodsBatchCode.Text)) return;
            string barCode = txtGoodsBatchCode.Text.Trim();
            int curIndex = lstOffShelves.FindIndex(x => x.GOODSBATCHCODE == barCode);
            if (curIndex < 0) return;
            dtGridOffShelves.Select(curIndex);
            this.dtGridOffShelves.SelectionBackColor = Color.Green;
            
 
        }
        //刷新数据
        private void RefData()
        {
            this.bsOffShelvesSource.DataSource = null;
            this.bsOffShelvesSource.DataSource = lstOffShelves;
            this.dtGridOffShelves.DataSource = this.bsOffShelvesSource;
            this.dtGridOffShelves.Refresh();
            //设置已扫描的为加亮
            SelectionBright();
        }
        //回车库位号
        private void cbbCellNo_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Enter) return;

            if (string.IsNullOrEmpty(cbbCellNo.Text.Trim()))
            {
                txtBatchNo.Focus();
            }
        }
        //回车批次号
        private void txtBatchNo_KeyDown(object sender, KeyEventArgs e)
        {
         
            if (e.KeyCode != Keys.Enter) return;

            if (string.IsNullOrEmpty(txtBatchNo.Text.Trim()))
            { 
                txtBatchNo.Focus();
            }
            else
            {
                btnShelves.Focus();
            }
        } 
        //回车商品批次号
        private void txtGoodsBatchCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Enter) return;

            if (string.IsNullOrEmpty(txtGoodsBatchCode.Text.Trim())) return;
            string gbCode = txtGoodsBatchCode.Text.Trim();
            if (gbCode.Length != 18 && gbCode.Length != 17 && gbCode.Length != 20)
            {
                MessageBox.Show("请扫描正确的商品批次条码！");
                txtGoodsBatchCode.SelectAll();
                return;
            }
            try
            {
                LocationGoodsInfo _LocationGoods = null;
                string barCode = gbCode.Substring(0, gbCode.Length - 8);
                if (lstOffShelves == null)
                {
                    MessageBox.Show("请先获取指令下架数据！");
                    return;
                }
                int curIndex = lstOffShelves.FindIndex(x => x.GOODSBATCHCODE == gbCode);
                int curBCodeIndex = lstOffShelves.FindIndex(x => x.GOODSCODE == barCode);
                if (curIndex >= 0)
                {
                    //lstOffShelves[curIndex].QTYEXCE += 1;
                    txtQty.Text = GetRestQty(gbCode).ToString(); ;
                    //Sort(lstOffShelves[curIndex]);
                }
                else if (curBCodeIndex >= 0 && curIndex < 0 && string.IsNullOrEmpty(lstOffShelves[curBCodeIndex].GOODSBATCHCODE))
                {
                    //检验商品是否先进先出
                    List<LocationGoodsInfo> checklgs = Duty.OffShelvesUIRule.NewInstance.CheckGetLocationGoodsInfo(gbCode);
                    if (checklgs != null)
                    {
                        foreach (LocationGoodsInfo lgItem in checklgs)
                        {
                            if (lstOffShelves.FindIndex(x => x.GOODSBATCHCODE == lgItem.GOODSBATCHCODE) < 0)
                            {
                                string msg = string.Format("该商品存在更早批次库存,\n商品批次号:{0},\n名称:{1},库存:{2}{3}!\n是否重新扫描条码?",
                                    lgItem.GOODSBATCHCODE, lgItem.GOODSNAME, lgItem.INVQTY, lgItem.UNITNAME);
                                if (MessageBoxEx.Question(msg) == DialogResult.Yes)
                                {
                                    txtGoodsBatchCode.SelectAll();
                                    return;
                                }
                            }
                        }
                    }
                    //获取库存数据
                    _LocationGoods = Duty.OffShelvesUIRule.NewInstance.GetLocationGoodsInfo(gbCode);
                    if (_LocationGoods == null)
                    {
                        MessageBox.Show("没有找到匹配的数据！");
                        txtGoodsBatchCode.SelectAll();
                        return;
                    }
                    lstOffShelves[curBCodeIndex].GOODSBATCHCODE = gbCode;
                    lstOffShelves[curBCodeIndex].INVQTY=_LocationGoods.INVQTY;
                    //Sort(lstOffShelves[curBCodeIndex]); 
                    txtQty.Text = GetRestQty(gbCode).ToString();
                }
                else if (curBCodeIndex >= 0)
                {
                    //检验商品是否先进先出
                    List<LocationGoodsInfo> checklgs = Duty.OffShelvesUIRule.NewInstance.CheckGetLocationGoodsInfo(gbCode);
                    if (checklgs != null)
                    {
                        foreach (LocationGoodsInfo lgItem in checklgs)
                        {
                            if (lstOffShelves.FindIndex(x => x.GOODSBATCHCODE == lgItem.GOODSBATCHCODE) < 0)
                            {
                                string msg = string.Format("该商品存在更早批次库存,\n商品批次号:{0},\n名称:{1},库存:{2}{3}!\n是否重新扫描条码?",
                                    lgItem.GOODSBATCHCODE, lgItem.GOODSNAME, lgItem.INVQTY, lgItem.UNITNAME);
                                if (MessageBoxEx.Question(msg) == DialogResult.Yes)
                                {
                                    txtGoodsBatchCode.SelectAll();
                                    return;
                                }
                            }
                        }
                    }
                    //获取库存数据
                    _LocationGoods = Duty.OffShelvesUIRule.NewInstance.GetLocationGoodsInfo(gbCode);
                    if (_LocationGoods == null)
                    {
                        MessageBox.Show("没有找到匹配的数据！");
                        txtGoodsBatchCode.SelectAll();
                        return;
                    }

                    //添加指令下架商品批次
                    OffShelvesInfo offshelvesItem = new OffShelvesInfo();
                    //offshelvesItem = lstOffShelves[curBCodeIndex]; 
                    offshelvesItem.GOODSCODE = lstOffShelves[curBCodeIndex].GOODSCODE;
                    offshelvesItem.BATCHNO = lstOffShelves[curBCodeIndex].BATCHNO;
                    offshelvesItem.CELLNO = lstOffShelves[curBCodeIndex].CELLNO;
                    offshelvesItem.CREATOR = lstOffShelves[curBCodeIndex].CREATOR;
                    offshelvesItem.EDITOR = lstOffShelves[curBCodeIndex].EDITOR;
                    offshelvesItem.FLAG = lstOffShelves[curBCodeIndex].FLAG;
                    offshelvesItem.GOODSCODE = lstOffShelves[curBCodeIndex].GOODSCODE;
                    offshelvesItem.GOODSID = lstOffShelves[curBCodeIndex].GOODSID;
                    offshelvesItem.GOODSNAME = lstOffShelves[curBCodeIndex].GOODSNAME;
                    offshelvesItem.LOCATIONCODE = lstOffShelves[curBCodeIndex].LOCATIONCODE;
                    offshelvesItem.LOCATIONID = lstOffShelves[curBCodeIndex].LOCATIONID;
                    offshelvesItem.OFFSHELVESID = lstOffShelves[curBCodeIndex].OFFSHELVESID;
                    offshelvesItem.QTY = lstOffShelves[curBCodeIndex].QTY;
                    offshelvesItem.QTYEXCE = 0;
                    offshelvesItem.INVQTY = _LocationGoods.INVQTY;
                    offshelvesItem.REMARK = lstOffShelves[curBCodeIndex].REMARK;
                    offshelvesItem.WAREHOUSECODE = lstOffShelves[curBCodeIndex].WAREHOUSECODE;
                    offshelvesItem.WAREHOUSEID = lstOffShelves[curBCodeIndex].WAREHOUSEID;
                    offshelvesItem.GOODSBATCHCODE = gbCode;
                    offshelvesItem.UNITNAME = lstOffShelves[curBCodeIndex].UNITNAME;

                    lstOffShelves.Add(offshelvesItem);
                    txtQty.Text = GetRestQty(gbCode).ToString();
                    //Sort(offshelvesItem);

                }
                else
                {
                    MessageBoxEx.Show("该商品批次无匹配数据");
                    txtGoodsBatchCode.SelectAll();
                    return;
                }
 
                RefData();
                txtQty.Focus();
                txtQty.SelectAll();
            }
            catch (Exception ex)
            {
                txtGoodsBatchCode.Focus();
                txtGoodsBatchCode.SelectAll();
                WoChu.CF.BaseFrame.Util.MessageBoxEx.Show(ex);
            }
            finally
            {
                //txtGoodsBatchCode.Focus();
                //txtGoodsBatchCode.SelectAll();
            }
            
        }
        //回车数量
        private void txtQty_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Enter) return;
 
            if(string.IsNullOrEmpty(txtQty.Text.Trim()))return;

            if (string.IsNullOrEmpty(txtGoodsBatchCode.Text.Trim())) return;
 
            try
            {
                try
                {
                    decimal qty = Convert.ToDecimal(txtQty.Text.Trim());
                }
                catch
                {
                    WoChu.CF.BaseFrame.Util.MessageBoxEx.Show("输入的数量不正确!");
                    this.txtQty.Text = string.Empty;
                    this.txtQty.Focus();
                    return;
                }

                decimal offQty = Convert.ToDecimal(txtQty.Text.Trim());
                if(offQty<=0)
                {
                    MessageBox.Show("下架数量不能小于等于0！");
                    return;
                }
                string gbCode = txtGoodsBatchCode.Text.Trim();
                int curIndex = lstOffShelves.FindIndex(x => x.GOODSBATCHCODE == gbCode);
                if (curIndex >= 0)
                {
                     
                    decimal invQty = lstOffShelves[curIndex].INVQTY;
                    decimal restQty = lstOffShelves[curIndex].QTY;
                    List<OffShelvesInfo> lstgbs = lstOffShelves.FindAll(x => x.GOODSCODE == lstOffShelves[curIndex].GOODSCODE && x.GOODSBATCHCODE != gbCode);
                    foreach(OffShelvesInfo curItem in lstgbs)
                    { 
                        restQty -= curItem.QTYEXCE;
                    }
                    if (offQty > invQty)
                    {
                        //if(MessageBoxEx.Question(string.Format("下架数量:{0},大于库存数量:{1},是否继续下架？",offQty,invQty))==DialogResult.No)
                        MessageBox.Show(string.Format("下架数量:{0},大于库存数量:{1},请重新输入下架数量！", offQty, invQty));
                        return;
                    }
                    if (offQty > restQty)
                    {
                        if (MessageBoxEx.Question(string.Format("下架数量:{0},大于剩余下架数量:{1},是否继续下架？", offQty, restQty)) == DialogResult.No)
                            return;
                    }
                    lstOffShelves[curIndex].QTYEXCE = offQty;
                    OffShelvesInfo lastItem = lstOffShelves[curIndex]; 
                    lstOffShelves.RemoveAt(curIndex);
                    lstOffShelves.Add(lastItem); 
                    //this.bsOffShelvesSource.DataSource = null;
                    //this.bsOffShelvesSource.DataSource = lstOffShelves;
                    //this.dtGridOffShelves.DataSource = this.bsOffShelvesSource;
                    this.dtGridOffShelves.Refresh(); 
 
                    txtQty.Text = string.Empty;
                    txtGoodsBatchCode.Text = string.Empty; 
                    txtGoodsBatchCode.Focus();
  
                }
                else
                {
                    txtGoodsBatchCode.Focus();
                    txtGoodsBatchCode.SelectAll();
                    WoChu.CF.BaseFrame.Util.MessageBoxEx.Show("请重新扫描商品批次号！"); 
                }
               
            }
            catch (Exception ex)
            {
                WoChu.CF.BaseFrame.Util.MessageBoxEx.Show(ex);
            }
 
        } 
        //提交
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (lstOffShelves == null || lstOffShelves.Count == 0)
                {
                    MessageBox.Show("数据为空，无法提交！");
                    return;
                }
                
                Cursor.Current = Cursors.WaitCursor;

                //if (WoChu.CF.BaseFrame.Util.MessageBoxEx.Question("是否绑定箱号？") == DialogResult.Yes)
                //{
                //    if (goodsBox == null || string.IsNullOrEmpty(goodsBox.GOODSBOXCODE))
                //    {
                //        //this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                //        FrmBindBoxCode fbbc = new FrmBindBoxCode(true);
                //        //fbbc.StartPosition = FormStartPosition.CenterParent;
                //        fbbc.ShowDialog();
                //    }
                //    if (WoChu.CF.BaseFrame.Util.MessageBoxEx.Question("是否提交？绑定箱号：." + goodsBox.GOODSBOXCODE + ",波次：" + goodsBox.BATCHNO + ",配送时间：" + goodsBox.RATIONDATE + " , 修改箱号等信息请退出下架界面！") == DialogResult.No) return;

                //}

                int isNullCount = lstOffShelves.FindAll(x => !string.IsNullOrEmpty(x.GOODSBATCHCODE) && x.QTYEXCE == 0).Count;
                if (isNullCount > 0)
                {
                    MessageBox.Show("有已扫描商品，下架数量为0的数据，请检查！");
                    return;
                }
                List<OffShelvesInfo> lstOffQtys=lstOffShelves.FindAll(x => x.QTYEXCE > 0);
                if(lstOffQtys==null || lstOffQtys.Count==0)
                {
                    MessageBox.Show("指令数据下架数量均等于0，\n请重新扫描下架数据！");
                    return;
                }
                int bgCodeNullCount=lstOffShelves.FindAll(x=>string.IsNullOrEmpty(x.GOODSBATCHCODE)).Count;
                if(bgCodeNullCount>0)
                {
                    if (MessageBoxEx.Question("有未扫描的商品数据,是否继续提交？") == DialogResult.No)
                        return;
                } 
                string gCode = null;
                foreach (OffShelvesInfo oslItem in lstOffQtys)
                {
                    if (oslItem.GOODSCODE == gCode)
                        continue;
                    gCode = oslItem.GOODSCODE;
                    decimal qtySum = lstOffShelves.FindAll(x => x.GOODSCODE == oslItem.GOODSCODE).Sum(x => x.QTYEXCE);
                    if (qtySum != oslItem.QTY)
                    {
                        if (MessageBox.Show("同一商品：" + oslItem.GOODSNAME + ",实下数[" + qtySum + "]与计划数[" + oslItem.QTY + "]不相等,是否提交？", "提示消息", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
                        {
                            Sort(oslItem);
                            return;
                        }
                    }
                }
 
                if (lstOffQtys.Count() > 0)
                {
                    //DateTime rationdate = goodsBox.RATIONDATE.HasValue ? goodsBox.RATIONDATE.Value : DateTime.Parse("1900-01-01");
                    //DateTime rationdate = DateTime.Parse("1900-01-01");
                    //goodsBox.GOODSBOXCODE = "";
                    OutPutParams<bool> re = Duty.OffShelvesOrderUIRule.NewInstance.SetOffShelves(LoginBean.Instance.USERCODE, lstOffQtys);
 
                    if (re.Params)
                    {
                        lstOffShelves.Clear();
                        this.bsOffShelvesSource.DataSource = null;
                        this.dtGridOffShelves.DataSource = this.bsOffShelvesSource;
                        this.dtGridOffShelves.Refresh();

                        txtGoodsBatchCode.Text = string.Empty;
                        txtBatchNo.Text = string.Empty;
                        txtQty.Text = string.Empty;
                        txtBatchNo.Focus();

                        WoChu.CF.BaseFrame.Util.MessageBoxEx.Show("指令下架提交成功！");
                    }
                    else
                    {
                        MessageBox.Show("提交失败！\n" + re.Message);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                WoChu.CF.BaseFrame.Util.MessageBoxEx.Show(ex);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        //关闭窗体事件
        private void FrmOffShelvesOrder_Closed(object sender, EventArgs e)
        {
            //System.Reflection.Assembly ass = System.Reflection.Assembly.Load("WoChu.RfClient.Login");
            //Type type = ass.GetType("WoChu.RfClient.Login.FrmMain");
            //Object o = Activator.CreateInstance(type);
            //System.Reflection.MethodInfo mi = type.GetMethod("Show");

            //mi.Invoke(o, null);
            goodsBox = null;
            lstOffShelves = null;
            lstOffCellNo = null;
            this.Close();
            this.Dispose();
        }
        //关闭窗体提示
        private void FrmOffShelvesOrder_Closing(object sender, CancelEventArgs e)
        {
            if (lstOffShelves != null)
            {
                if (lstOffShelves.Count > 0)
                {
                    if (MessageBox.Show("是否退出界面，将不保存界面数据？", "提示消息", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
                    {
                        e.Cancel = true;
                        return;
                    }
                }
            }
            
        }

        //剩余指令下架数量
        //private decimal GetRestOffQty(string gbCode)
        //{
        //    string barCode = gbCode.Substring(0, 10);

        //    decimal restQty =lstOffShelves.First(x=>x.BARCODE==barCode).QTY;
        //    List < OffShelvesInfo > lstoffQtys= lstOffShelves.FindAll(x => x.BARCODE == barCode && x.GOODSBATCHCODE != gbCode);
        //    foreach (OffShelvesInfo curItem in lstoffQtys)
        //    {
        //        restQty-=curItem.QTYEXCE;
        //    }
        //    return restQty; 
        //}

        //获取推荐下架数量
        private decimal GetRestQty(string gbCode)
        {
            string barCode = gbCode.Substring(0, 10);
            OffShelvesInfo curItem = lstOffShelves.Find(x => x.GOODSBATCHCODE == gbCode);
            List<OffShelvesInfo> lstItme = lstOffShelves.FindAll(x => x.GOODSCODE == barCode);
            if(curItem==null)
            {
                MessageBoxEx.Show("找不到该商品批次号的数据:"+gbCode);
                return 0;
            }
            decimal planQty = curItem.QTY;
            decimal offQty = 0;
            decimal restQty = 0;
            foreach (OffShelvesInfo Item in lstItme)
            {
                if (Item.GOODSBATCHCODE != curItem.GOODSBATCHCODE)
                    offQty += Item.QTYEXCE;
            }
            restQty = planQty - offQty;
            if (restQty <= 0)
            {
                MessageBox.Show(string.Format("该商品下架总数量{0}已满足计划数量{1},不需要再下架", offQty, planQty));
                return 0;
            }
            if (curItem.INVQTY < restQty)
            {
                decimal diffQty = restQty - curItem.INVQTY;
                //MessageBoxEx.Show(string.Format("该商品下架剩余数量：{0}\n大于当前商品批次库存：{1},\n还差：{2},可下架：{1} ", restQty, curItem.INVQTY, diffQty));
                return curItem.INVQTY;
            }
            else
            {
                //MessageBoxEx.Show(string.Format("下架剩余数量：{0}，可下架：{0}", restQty));
                return restQty;
            } 
        }

        private void dtGridOffShelves_DoubleClick(object sender, EventArgs e)
        {
            int curIndex = dtGridOffShelves.CurrentRowIndex;
            if (curIndex < 0) return;
            try
            {
                string gbCode = dtGridOffShelves[curIndex, 6].ToString();
                OffShelvesInfo curItem = lstOffShelves.Find(x => x.GOODSBATCHCODE == gbCode);
                string ltCode = curItem.LOCATIONCODE;
                string gbName = curItem.GOODSNAME;
                
                string Message = string.Format("货位:{0}, 名称:{1}, 商品批次号:{2} \n 是否删除该数据？", ltCode, gbName, gbCode);
                if (MessageBoxEx.Question(Message) == DialogResult.Yes)
                {
                    lstOffShelves.Remove(curItem);
  
                    this.bsOffShelvesSource.DataSource = null;
                    this.bsOffShelvesSource.DataSource = lstOffShelves;
                    this.dtGridOffShelves.DataSource = this.bsOffShelvesSource;
                    this.dtGridOffShelves.Refresh();
                }
            }
            catch (Exception ex)
            {
                TraceEx.Write(ex.Message);
                WoChu.CF.BaseFrame.Util.MessageBoxEx.Show("删除数据失败!");
            }
            finally
            {
                txtGoodsBatchCode.Focus(); 
                txtGoodsBatchCode.SelectAll();
            }
        }
 
        
    }
}